function write_image(fname , im);

%only could use the gray image

f = fopen(fname, 'w');

im = im';

[dim1 dim2] = size(im);

if f < 0,
    x = [];
    return;
end;

s(1) = uint32(dim1);
s(2) = uint32(dim2);

fwrite(f, s, 'uint32');
fwrite(f , im , 'double');

fclose all;